
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:massagist/manager/config.dart';
import 'package:massagist/manager/request.dart';
import 'package:massagist/pages/phone_auto_page.dart';

import '../generated/l10n.dart';

typedef DialogCallback = void Function(int index);

void showAcctravelMoreDialog(BuildContext context, DialogCallback callback) {
  showModalBottomSheet(
    context: context,
    shape: RoundedRectangleBorder(
      borderRadius: BorderRadius.vertical(top: Radius.circular(12.sp)),
    ),
    builder: (BuildContext context) {
      return Container(
        height: 186.sp,
        child: Column(
          children: [
            GestureDetector(
              child: Container(
                margin: EdgeInsets.only(left: 12.sp, right: 12.sp, top: 16.sp),
                width: double.infinity,
                height: 45.sp,
                  decoration: BoxDecoration(
                    color: Color(0xFFFF5147),
                    borderRadius: BorderRadius.circular(8.sp),
                  ),
                child: Center(
                  child: Text(
                    S.current.TO_BLACK_TEXT,
                    style: TextStyle(color: Colors.white, fontSize: 17.sp),
                  ),
                ),
              ),
              onTap: () {
                Navigator.of(context).pop();
                callback(0);
              },
            ),

            GestureDetector(
              child: Container(
                margin: EdgeInsets.only(left: 12.sp, right: 12.sp, top: 12.sp),
                width: double.infinity,
                height: 45.sp,
                decoration: BoxDecoration(
                  border: Border.all(
                    color: Color(0xFF00CA7E),
                    width: 1.sp,
                  ),
                  color: Colors.white,
                  borderRadius: BorderRadius.circular(8.sp),
                ),
                child: Center(
                  child: Text(
                    S.current.COMPLAIN_TEXT,
                    style: TextStyle(color: Color(0xFF00CA7E), fontSize: 17.sp),
                  ),
                ),
              ),
              onTap: () {
                Navigator.of(context).pop();
                callback(1);
              },
            ),

            GestureDetector(
              child: Container(
                margin: EdgeInsets.only(left: 12.sp, right: 12.sp, top: 12.sp),
                width: double.infinity,
                height: 40.sp,
                decoration: BoxDecoration(
                  color: Color(0xFFEEEEEE),
                  borderRadius: BorderRadius.circular(8.sp),
                ),
                child: Center(
                  child: Text(
                    S.current.CANCEL_TEXT,
                    style: TextStyle(color: Color(0xFF999999), fontSize: 17.sp),
                  ),
                ),
              ),
              onTap: () {
                Navigator.of(context).pop();
              },
            ),
          ],
        ),
      );
    },
  );
}

void showTechnicianBusyDialog(BuildContext context) {
  showDialog(
    context: context,
    builder: (BuildContext context) {
      return AlertDialog(
        contentPadding: EdgeInsets.zero,
        content: Container(
          height: 100.sp,
          decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.circular(8.sp),
          ),
          child: Column(
            children: [
              Container(
                alignment: Alignment.topRight,
                child: GestureDetector(
                  child: Container(
                    width: 30.sp, height: 30.sp,
                    child: Icon(Icons.close),
                  ),
                  onTap: () {
                    Navigator.of(context).pop();
                  },
                ),
              ),
              Container(
                height: 40.sp,
                alignment: Alignment.center,
                child: Text(
                  S.current.IN_SERVICE_REMIND,
                  style: TextStyle(color: Colors.black, fontSize: 13.sp),
                  maxLines: 2,
                ),
              ),
              GestureDetector(
                child: Container(
                  child: Center(
                    child: Text(
                      S.current.EXCHANGE_NEXT,
                      style: TextStyle(color: Colors.blueAccent, fontSize: 13.sp),
                    ),
                  ),
                ),
                onTap: () {
                  Navigator.of(context).pop();
                },
              ),
            ],
          ),
        ),
      );
    },
  );
}

void showCloseAccountDialog(BuildContext context) {
  showDialog(
    context: context,
    builder: (BuildContext context) {
      return AlertDialog(
        contentPadding: EdgeInsets.zero,
        content: Container(
          height: 135.sp,
          decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.circular(8.sp),
          ),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Column(
                children: [
                  Container(
                    margin: EdgeInsets.only(top: 34.sp),
                    child: Text(S.current.DIALOG_CONFIRM_CLOSE, style: TextStyle(fontWeight: FontWeight.w500, fontSize: 18.sp, color: Color(0xFF333333)),),
                  ),
                ],
              ),
              Container(
                child: Column(
                  children: [
                    Divider( color: Color(0xFFDDDDDD), height: 1, thickness: 1, ),
                    Row(
                      children: [
                        Expanded(child:GestureDetector(
                          child:  Container(
                            height: 50.sp,
                            child: Text(S.current.DIALOG_CANCEL, style: TextStyle(fontWeight: FontWeight.w500, fontSize: 18.sp, color: Color(0xFF333333)),),
                            alignment: Alignment.center,
                          ),
                          onTap: () {
                            Navigator.of(context).pop();
                          },
                        )),
                        Expanded(child: GestureDetector(
                          child: Container(
                            height: 50.sp,
                            child: Text(S.current.DIALOG_CONFIRM, style: TextStyle(fontWeight: FontWeight.w500, fontSize: 18.sp, color: Color(0xFF00CA7E)),),
                            alignment: Alignment.center,
                          ), onTap: () async {
                          // Navigator.of(context).pop();
                          var result = await Request.closeAccount();
                          if (result.code == RESPONSE_SUCCESS) {
                            Navigator.pushAndRemoveUntil(
                              context,
                              MaterialPageRoute(builder: (context) => PhoneAutoPage()),
                                  (route) => false,
                            );
                          } else {
                            Navigator.of(context).pop();
                          }
                        },
                        ))
                      ],
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    )
                  ],
                ),
              )
            ],
          ),
        ),
      );
    },
  );
}

void showLogoutAccountDialog(BuildContext context) {
  showDialog(
    context: context,
    builder: (BuildContext context) {
      return AlertDialog(
        contentPadding: EdgeInsets.zero,
        content: Container(
          height: 135.sp,
          decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.circular(8.sp),
          ),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Column(
                children: [
                  Container(
                    margin: EdgeInsets.only(top: 21.sp),
                    child: Text(S.current.MINE_LOGOUT, style: TextStyle(fontWeight: FontWeight.w500, fontSize: 18.sp, color: Color(0xFF333333)),),
                  ),
                  Container(
                    margin: EdgeInsets.only(top: 9.sp),
                    child: Text(S.current.MINE_CONFIRM_LOGOUT, style: TextStyle(fontWeight: FontWeight.w500, fontSize: 15.sp, color: Color(0xFF999999)),),
                  ),
                ],
              ),
              Container(
                child: Column(
                  children: [
                    Divider( color: Color(0xFFDDDDDD), height: 1, thickness: 1, ),
                    Row(
                      children: [
                        Expanded(child:GestureDetector(
                          child:  Container(
                            height: 50.sp,
                            child: Text(S.current.DIALOG_CANCEL, style: TextStyle(fontWeight: FontWeight.w500, fontSize: 18.sp, color: Color(0xFF333333)),),
                            alignment: Alignment.center,
                          ),
                          onTap: () {
                            Navigator.of(context).pop();
                          },
                        )),
                        Expanded(child: GestureDetector(
                          child: Container(
                            height: 50.sp,
                            child: Text(S.current.DIALOG_CONFIRM, style: TextStyle(fontWeight: FontWeight.w500, fontSize: 18.sp, color: Color(0xFF00CA7E)),),
                            alignment: Alignment.center,
                          ), onTap: () async {

                          var logoutResult = await Request.requestLogout();
                          if (logoutResult.code == RESPONSE_SUCCESS) {
                            Navigator.pushAndRemoveUntil(
                              context,
                              MaterialPageRoute(builder: (context) => PhoneAutoPage()),
                                  (route) => false,
                            );
                          } else {
                            Navigator.of(context).pop();
                          }
                        },
                        ))
                      ],
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    )
                  ],
                ),
              )
            ],
          ),
        ),
      );
    },
  );
}